<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>邮箱验证</title>
    <style>
        .box{
            display: flex;
            width: 310px;
            position: relative;
        }
        span{
            position: absolute;
            right: 0;
            top: 0;
        }
        .conform{
            color: #58bc58;
        }
        .unConform{
            color: red;
        }
    </style>
</head>
<body>
    <div class="box">
        <input type="text"><button id='btn'>验证</button>
        <span class="unConform"></span>
    </div>

    <script>
        /* 
            邮箱以这些结束 .com/.cn/.sina/.net
        */

        // 获取元素
        var btn = document.querySelector('#btn');
        var span = document.querySelector('span');
        // 正则表达式
        var reg = /^[0-9a-zA-Z_]{6,12}@(163|126|qq)\.(com|cn|net|sina)$/;

        btn.onclick = function(){
            var email = document.querySelector('input').value;
            var isConform = reg.test(email);
            // console.log(isConform);
            if(isConform){
                span.innerText = '通过验证';
                span.className = 'conform';
            }else{
                span.innerText = '不符合要求';
                span.className = 'unConform';
            }
        }
    </script>
</body>
</html>